package com.four.commodity.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {														//	   useUnicode=true&characterEncoding=UTF-8
		private static final String url = "jdbc:mysql://192.168.8.8:3306/dianshang?useUnicode=true&characterEncoding=UTF-8";//url指向要访问的数据库名jxgl
		private static final String user = "caoliwen";//MySQL配置时的用户名
		private static final String password = "123456";
		static {
			try {
				DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		public static Connection getConnection() {
			Connection conn = null;
			try {
				conn = DriverManager.getConnection(url, user, password);
			}catch(SQLException e) {
				e.printStackTrace();
			}
			return conn;
		}
		public static void closeResource(Connection conn, PreparedStatement ps, ResultSet rs) {
			try {
			if(rs != null && !rs.isClosed());
				rs.close();
			}catch (SQLException e) {
			e.printStackTrace();
		}
			try {
				if(ps != null && !ps.isClosed());
					ps.close();
				}catch (SQLException e) {
				e.printStackTrace();
			}
			try {
				if(conn != null && !conn.isClosed());
					conn.close();
				}catch (SQLException e) {
				e.printStackTrace();
			}
	}

	}
